const chalk = require('chalk');
const symbols = require('log-symbols');
const Inquirer = require('inquirer');

const askPrompt = async (config, condition) => {
  const answers = await Inquirer.prompt(config);
  const { verify, msg } = condition;
  if (!verify) return {};
  if (!verify(answers)) {
    console.log(symbols.error, chalk.red(msg));
    const res = await askPrompt(config, condition);
    return res;
  }
  return answers;
};

module.exports = {
  askPrompt,
};
